<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="whf.framework.web.Constants"%>
<%@ page import="whf.framework.util.BeanUtils" %>

<%@taglib uri="/WEB-INF/tlds/framework.tld" prefix="framework"%>
<%@taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/common/inc/select.jsp" %>
<% String queryString = (String)request.getAttribute("queryString"); 
int pageSize = queryString == null? 15: 100;
%>
</head>
<body>
<framework:msg />
<html:form action='<%=  (String)request.getAttribute(Constants.STRUTS_PATH) %>' method="post">
<html:hidden property="webMethod" value="preparePermissions" />
<html:hidden property="id" />
<framework:ext ignoreParams="_$_trc" />
<table width="80%" align='center'>
	<tr height=15 valign='bottom'>
		<td width="10%">名称</td>
		<td colspan=4><framework:attr source="selectedRole" attr="name" /></td>
	</tr>
	<tr height=15 valign='top'>
		<td width="10%">说明</td>
		<td colspan=4><framework:attr source="selectedRole" attr="remarks" /></td>
	</tr>
</table>
<framework:query view="SYSTEM-OBJECT-QUERY" displayColumnCount="2" />
<framework:table boClassName="whf.framework.meta.entity.Object" wrapClass="whf.framework.security.helper.PermissionWrapper" 
	editable="false" navPosition="both" pkStyle="counter"
	rowExt="true" queryString="<%= queryString %>"> pageSize="<%= pageSize %>"
	<framework:column property="name" displayTitle="名称" />
	<framework:column property="remarks" displayTitle="说明" />
	<framework:column property="permissions" displayTitle="权限" outputDirect="true">
		<input type='hidden' name='boClassName' value="${meta.boClassName}" />
		<%request.setAttribute("perms", ((whf.framework.security.helper.PermissionWrapper)request.getAttribute("currentRow")).getPermissions());%>
		<framework:selections source="perms" selectedValues="<%= (String)request.getAttribute("selectedPermIds") %>" selectionName="perm" valueProperty="id" textProperty="name" colCount="5" multiSelect="true"/>
	</framework:column>
	<framework:rowext>
		<input type='button' value= '全  选' onclick='selectAllPerms("<%= BeanUtils.getPropertyListString(((whf.framework.security.helper.PermissionWrapper)request.getAttribute("currentRow")).getPermissions(), "id") %>","${id}")'>
		<input type='button' value= '全不选' onclick='unselectAllPerms("<%= BeanUtils.getPropertyListString(((whf.framework.security.helper.PermissionWrapper)request.getAttribute("currentRow")).getPermissions(), "id") %>","${id}")'>
	</framework:rowext>
</framework:table>
<framework:funcbtn operation="managePermissions" valueKey="form.submit" />
<input type='reset' value='<bean:message key="form.reset" />'>
</html:form>
</body>
<script>
function selectAllPerms(idstr){
	var ids = idstr.split(";");
	var eles = document.getElementsByName("perm");
	for(i=0;i< eles.length;i++){
		for(j=0;j<ids.length;j++){
			if(eles[i].value == ids[j]){
				eles[i].checked=true;
				break;
			}
		}
	}
}
function unselectAllPerms(idstr){
	var ids = idstr.split(";");
	var eles = document.getElementsByName("perm");
	for(i=0;i< eles.length;i++){
		for(j=0;j<ids.length;j++){
			if(eles[i].value == ids[j]){
				eles[i].checked=false;
				break;
			}
		}
	}
}
</script>
</html>